﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace Treasland.MassiveGridMap.Editor {

    public enum enConnectionPoint {
        InPoint,
        OutPoint,
    }

    public enum enNodeType {
        MapNode,
        LayerNode,
        ConnectionPoint,
        Connection,
    }

    public enum enNodeDragState {
        Free,
        Lock,
        ReadyDrag
    }

    public class Node {
        public Rect rect;

        protected enNodeType nodeType;
        protected enNodeDragState nodeDragState;

        public Node(enNodeType _type) {
            nodeType = _type;
        }

        public virtual bool ProcessEvent(Event e) {
            if(e.type == EventType.MouseDown) {
                if(e.button == 2) {
                    nodeDragState = enNodeDragState.Lock;
                }
            }

            if (e.type == EventType.MouseUp) {
                if (e.button == 0) {
                    if (nodeDragState != enNodeDragState.Lock) {
                        nodeDragState = enNodeDragState.Free;
                    }
                }
                if (e.button == 2) {
                    nodeDragState = enNodeDragState.Free;
                }
            }

            return false;
        }

        public virtual void Draw() {

        }

        public virtual void Drag(Vector2 delta) {
            rect.position += delta;
        }

        public virtual void ForceDrag(Vector2 delta) {
            rect.position += delta;
        }
    }
}
